<?php
class Util{
	static function AddLog($content){
		$db = getDb();
		$db->connect();
		$db->execute("INSERT INTO log_t(uid,logtime,contents) VALUES({0},{1},{2})",array(Auth::GetData('uid'),date("Y-m-d H:i:s"),$content));
	}
	static function HaveRight_And($right_arr){
		if(!is_array($right_arr))
			$right_arr = array(intval($right_arr));
		$db = getDb();
		$db->connect();
		for($i=0;$i<count($right_arr);$i++){
			$rid = intval($right_arr[$i]);
			$uid = intval(Auth::GetData('uid'));			
			$re = $db->fetch("SELECT * FROM right_t WHERE uid={0} AND rid={1}",array($uid,$rid));
			if(count($re) != 1)
				return false;
		}
		return true;
	}
	static function ValidateRight($right_arr,$type = 'or'){
		$re = false;
		if(strtolower($type) == 'or') $re = Util::HaveRight_Or($right_arr);
		elseif(strtolower($type) == 'and') $re = Util::HaveRight_And($right_arr);
		else die('parameter error in function ValidateRight!');
		if(!$re)
			PageBase::Go('../home/error.php',"对不起，您没有权限执行该命令.");
	}
	static function HaveRight_Or($right_arr){
		if(!is_array($right_arr))
			$right_arr = array(intval($right_arr));
		$db = getDb();
		$db->connect();
		for($i=0;$i<count($right_arr);$i++){
			$rid = intval($right_arr[$i]);
			$uid = intval(Auth::GetData('uid'));			
			$re = $db->fetch("SELECT * FROM right_t WHERE uid={0} AND rid={1}",array($uid,$rid));
			if(count($re) == 1)
				return true;
		}
		return false;
	}
}
?>